package yt.kpool.activity;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import yt.kpool.MainActivity;
import yt.kpool.R;
import yt.kpool.activity.salesman.SalesmanMainActivity;
import yt.kpool.activity.setting.PaySetDetailAc;
import yt.kpool.base.BaseApplication;
import yt.kpool.bean.CurrencyList;
import yt.kpool.network.HttpUtils;
import yt.kpool.network.MyGson;
import yt.kpool.network.NetHelperNew;
import yt.kpool.util.NetWorkUtil;
import yt.kpool.util.SPUtil;
import yt.kpool.util.ToastUtil;
import yt.kpool.util.imageUtil.GlideUtil;
import yt.kpool.view.dialog.ErrorDialog;

/**
 * 欢迎页
 */
public class WelcomeActivity extends AppCompatActivity {

    @BindView(R.id.ll_top)
    LinearLayout ll_top;
    @BindView(R.id.tv_content)
    TextView tv_content;
    private int delayMills = 3000;//延迟跳转的时间
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏

        setContentView(R.layout.activity_welcome);
        ButterKnife.bind(this);
        openAPP();
        startacvity();
    }

    /**
     * 跳转页面
     */
    private void startacvity() {


         Animation mShowAction = AnimationUtils.loadAnimation(this, R.anim.alpha_in);
         mShowAction.setStartOffset(1500);
         Animation mShowAction2 = AnimationUtils.loadAnimation(this, R.anim.translate_in);
         mShowAction2.setStartOffset(1000);
         mShowAction2.setFillAfter(true);
         ll_top.startAnimation(mShowAction2);
         tv_content.setVisibility(View.VISIBLE);
         tv_content.startAnimation(mShowAction);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
//                SPUtil spUtil = new SPUtil(BaseApplication.context, BaseApplication.FILENAME);
//                String token = spUtil.getString(BaseApplication.TOKEN, "");
//                if ("".equals(token))
//                {
//                    //无token跳登录页
//                    Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
//                    intent.putExtra("isStrart",true);
//                    startActivity(intent);
//                }else
//                {
//
//                }

                SPUtil spUtil = new SPUtil(BaseApplication.context, BaseApplication.FILENAME);
                int type=spUtil.getInt(BaseApplication.UserType, 0);
                if (type==5){
                    //业务员
                    //跳转首页
                    startActivity(new Intent(getApplicationContext(), SalesmanMainActivity.class));
                    finish();
                }else {
                    //跳转首页
                    startActivity(new Intent(getApplicationContext(), MainActivity.class));
                    finish();
                }

            }
        }, delayMills);

    }

    /**
     * 打开app默认
     */
    private void openAPP() {
            NetHelperNew.OpenAPP(new HttpUtils.HttpCallback() {
                @Override
                public void onSuccess(String data) {
                   Log.i("-->",""+data);
                }


                @Override
                public void onError(String msg) {
                    super.onError(msg);
                    Log.i("-->",""+msg);
                }
            });




    }
}
